Cortex-M backend: Refactor ConvertToCortexMPass#20070
Conversation
Change to use the general AtenToDialectPass structure. Removes the 1-1 ensure check as it was to restrictive, cortex-m backend needs to both insert scratch nodes and for BMM an additional transpose at the time of dialect replacement. Bonus small fix: Moves yolo import into test to avoid download at test collection time Signed-off-by: Adrian Lundell <adrian.lundell@arm.com> Change-Id: Ic62964522704d31f75c653bc265bcce02ce375c6
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20070
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New FailuresAs of commit d46edf4 with merge base e56be3e ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Pull request overview
Refactors the Cortex-M backend’s ATen→dialect lowering to use the shared AtenToDialectPass substitution/decorator structure (replacing ConvertToCortexMPass), and relaxes the prior 1:1 “call_function count preserved” postcondition to allow scratch/aux node insertion (needed for CMSIS-NN scratch buffers and BMM transpose handling). Also adjusts the YOLO test to avoid triggering weights download during test collection.
Changes:
- Remove the
requires()/ensures()“call_function count preserved” check fromAtenToDialectPassand delete the corresponding test. - Introduce
AtenToCortexMPassand wire it into the Cortex-M pass manager in place ofConvertToCortexMPass. - Move YOLO model instantiation/weights loading into the test body to avoid collection-time side effects.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backends/transforms/test/test_aten_to_dialect_pass.py | Removes the test that asserted the old 1:1 call_function count invariant. |
| backends/transforms/aten_to_dialect_pass.py | Removes the 1:1 substitution invariant enforcement (requires/ensures). |
| backends/cortex_m/test/models/test_yolo11.py | Defers YOLO weights/model creation to test runtime to avoid collection-time downloads. |
| backends/cortex_m/passes/cortex_m_pass_manager.py | Switches the pass pipeline to use AtenToCortexMPass. |
| backends/cortex_m/passes/aten_to_cortex_m_pass.py | New pass implementing Cortex-M dialect substitutions + scratch alloc sizing logic. |
| backends/cortex_m/passes/init.py | Updates public pass imports to expose AtenToCortexMPass. |
Comments suppressed due to low confidence (1)
backends/cortex_m/test/models/test_yolo11.py:28
McuTestCase.modelis typed astorch.nn.Module, but this test passesNonewith a type-ignore. This can hide real issues and could break if future test helpers start usingtest_case.model. Use a lightweight placeholder module instead so the dataclass contract stays valid.
"yolo11n": McuTestCase(
model=None, # type: ignore[arg-type]
example_inputs=lambda: (
torch.randn(1, 3, 640, 640).to(memory_format=torch.channels_last),
),
),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rascani
left a comment
There was a problem hiding this comment.
Can you also update backends/cortex_m/passes/BUCK?
Signed-off-by: Adrian Lundell <adrian.lundell@arm.com> Change-Id: Ida9d298a0bf57c18957fb9117244adf260aadc12
Done, can you verify that it looks correct? |
LGTM, thanks for doing that. |
Adapt _get_avg_pool2d_replacement from the old ConvertToCortexMPass class to a @register_dialect_substitution function on AtenToCortexMPass, matching the pattern established by pytorch#20070. Add casts to satisfy mypy's node.args union type. Add a structural assertion to test_dialect_avg_pool2d that verifies the scratch buffer size matches cmsis_nn.avgpool_buffer_size() for the given input/output dimensions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Change to use the general AtenToDialectPass structure, quantized_op_fusion_pass
to be changed similarly in an upcoming PR.
Removes the 1-1 ensure check as it was to restrictive, cortex-m backend needs to both insert scratch nodes and for BMM an additional transpose at the time of dialect replacement.
Bonus small fix: Moves yolo import into test to avoid download at test collection time
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani